/**************************************************************************
** Yabet is bloging editor tool that supports many blog's formats. It is very usefull for crossposting, allows easily to
** make posts to your blogs.
**
** Copyright (C) 2010 Valery Konchin <eeexception@gmail.com>
**
** This program is free software: you can redistribute it and/or modify
**     it under the terms of the GNU General Public License as published by
**     the Free Software Foundation, either version 3 of the License, or
**     (at your option) any later version.
**
**     This program is distributed in the hope that it will be useful,
**     but WITHOUT ANY WARRANTY; without even the implied warranty of
**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**     GNU General Public License for more details.
**
**     You should have received a copy of the GNU General Public License
**     along with this program.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

#ifndef IMAGESHACKIMAGEUPLOADER_H
#define IMAGESHACKIMAGEUPLOADER_H

#include "ImageUploader.h"
#include <QNetworkReply>
#include <QEventLoop>
#include "yabetloghandler.h"

class ImageShackImageUploader : public ImageUploader
{
    Q_OBJECT

public:
    static const QString IMAGESHACK_IMAGE_HOST;
    ImageShackImageUploader();
    QString uploadImage(QString imagePath, QString imageHosting);
private:
    static const YabetLogHandler *log;
    bool wasErrors;
    QString resultUrl;
    QEventLoop loop;
    QMap<QString, QString> mimeTypes;

    QString getMimeType(QString fileSuffix);
    QByteArray preparePostData(QString filePath, QString boundary);
private slots:
    void replyFinished(QNetworkReply *reply);
    void slotError(QNetworkReply::NetworkError error);
signals:
    void wasError(QString msg);
    void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
};

#endif // IMAGESHACKIMAGEUPLOADER_H
